package com.coupons.business.category.dao;

import java.util.List;

import com.coupons.business.category.dao.ICategoryDAO;
import com.coupons.business.common.exception.BaseCouponsAppException;
import com.coupons.business.common.vo.Category;
import com.coupons.business.common.vo.decorator.CategoryRowMapper;
import com.coupons.business.util.BaseUtilDAO;

public class CategoryDAO extends BaseUtilDAO implements ICategoryDAO{
	
	/*
	 * (non-Javadoc)
	 * @see com.coupons.business.category.dao.ICategoryDAO#createCategory(coGET_ALL_CATEGORYS_STATEMENTm.coupons.business.common.vo.Category)
	 * "INSERT INTO CATEGORY(CTGRY_ID,CTGRY_NAME,MRCHNT_ID,PARTNER_ID,DESCRIPTION," 
	 * +"STATUS,LAST_UPDT_USER,RANK,CRTN_DT,LAST_UPDT_DT) VALUES(?,?,?,?,?,?,?,?,SYSDATE,SYSDATE)";
	 */
	
	public void createCategory(Category objaCategory)
	throws BaseCouponsAppException 
	{
		int categoryId= getSequenceNextValue(SEQUENCE_NAME);
		Object objParams[] = new Object[] { 
		new Integer(categoryId),
		objaCategory.getCategoryName(),
		new Integer(objaCategory.getMerchantId()),
		new Integer(objaCategory.getPartnerId()),
		objaCategory.getDescription(),
		objaCategory.getStatus(),		
		objaCategory.getLastUpdatedUser(),
		new Integer(objaCategory.getRank())
		};		
		int rtnVal = this.saveOrUpdateOrDelete(CATEGORY_INSERT_STATEMENT.toString(), objParams);
		objaCategory.setCategoryId(categoryId);		
		System.out.println("executed dao");
		if(rtnVal <= 0) {			
			System.out.println("Unable to insert record into Category table");
			return;
		}
	}

/*
* (non-Javadoc)
* @see com.coupons.business.merchant.dao.IMerchantDAO#updateMerchant(com.coupons.business.common.vo.Merchant)
* 
*  UPDATE MERCHANT SET MERCHANT_NAME = ?, DESCRIPTION = ?,
*	STATUS=?, LCSN_END_DT=?, RANK=?, MERCHANT_OFFER_HEADER=?, MERCHANT_SITE_URL=?,
*	MERCHANT_EMBLEM=?,MERCHANT_ASSOCIATION_ID=?,
*	LAST_UPDT_USER=?, LAST_UPDT_DT=SYSDATE WHERE MERCHANT_ID = ?
*/
public void updateCategory(Category objaCategory)
	throws BaseCouponsAppException 
{
Object objParams[] = new Object[] {				
		objaCategory.getCategoryName(),								
		objaCategory.getDescription(),
		objaCategory.getStatus(),
		objaCategory.getRank(),				
		objaCategory.getLastUpdatedUser(),
		objaCategory.getMerchantId()
		};
int rtnVal = this.saveOrUpdateOrDelete(CATEGORY_UPDATE_STATEMENT.toString(), objParams);
System.out.println("executed dao");
if(rtnVal <= 0) {			
	System.out.println("Unable to insert record into Category table");
	return;
}
}

/*
* (non-Javadoc)
* @see com.coupons.business.merchant.dao.IMerchantDAO#getMerchant(int)
* SELECT * FROM PARTNER where MERCHANT_ID = ?
*/
public Category getCategory(int categoryId) throws BaseCouponsAppException 
{
try {
	Object objParams[] = new Object[]{new Integer(categoryId)};
	List<Object> list = this.findRecords(GET_CATEGORY_STATEMENT, objParams,new CategoryRowMapper());
	
	if (null!=list && list.size()>0){				
			return (Category)list.get(0);
	}
	else
		return null;
} catch (BaseCouponsAppException e) {			
	e.printStackTrace();
	throw e;
}		
}

/*
* (non-Javadoc)
* @see com.coupons.business.merchant.dao.IMerchantDAO#getAllMerchants()
* SELECT * FROM MERCHANT
*/
public List<Category> getAllCategorys(int partnerId, int merchantId ) throws BaseCouponsAppException 
{
try {
	Object objParams[] = new Object[] { new Integer(partnerId), new Integer(merchantId) };
	List list = this.findRecords(GET_ALL_CATEGORYS_STATEMENT, objParams,new CategoryRowMapper());
	return list;
} catch (BaseCouponsAppException e) {			
	e.printStackTrace();
	throw e;
	}
}
}

